<?php
/**
 * @license    GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML View class for the CommunalMeals Component
 *
 */

class CommunalMealsViewSignUpAuto extends JView
{
	function display($tpl = null)
	{
		global $option, $mainframe;
		
		// Get ids from request
		$eventTypeId = JRequest::getVar('event_type', NULL );
		
		// Get data from model
		$member = CMeals::readMember(CMealsFrontEndUtils::getCurrentMemberId());
		$eventType = CMeals::readEventType($eventTypeId);
		$autoSignUpList = CMeals::readAutoSignUpList(CMealsFrontEndUtils::getCurrentMemberId(), $eventType->id);
		$eventSubTypeList = CMeals::readEventSubTypeList($eventType->id);
		$categoryList = CMeals::readEventCategoryList($eventType->id);
		
		// Prepare lists etc.
		$lists = array();
		$participantsBySubTypeAndCategory = array();
		foreach ($autoSignUpList as $autoSignUp) {
			$key = $autoSignUp->event_subtype."_".$autoSignUp->category;
			$participantsBySubTypeAndCategory[$key] = $autoSignUp->participants;
		}
		$participantsList = array();
		for ($i = 0; $i < 10; $i++) {
			$participantsList[] = array('value' => $i, 'text' => $i);
		}
		$partVarNameArray = array();
		foreach ($eventSubTypeList as $eventSubType) {
			foreach ($categoryList as $category) {
				$key = $eventSubType->id."_".$category->id;
				$partVarName = "part_".$key; // names of the html post variables for number of participants in each category
				$partVarNameArray[] = $partVarName;
				$selectedValue = $participantsBySubTypeAndCategory[$key];
				$lists[$key] = JHTML::_('select.genericList', $participantsList, $partVarName, 'class="inputbox"', 'value', 'text', $selectedValue );
			}
		}
		
		// Pass data to template
		$this->assignRef( 'member', $member );
		$this->assignRef( 'eventType', $eventType );
		$this->assignRef( 'eventSubTypeList', $eventSubTypeList );
		$this->assignRef( 'autoSignUpList', $autoSignUpList );
		$this->assignRef( 'categoryList', $categoryList );
		$this->assignRef( 'lists', $lists );
		$this->assignRef( 'partVarNameArray', $partVarNameArray );
		$this->assignRef( 'option', $option );
		
		parent::display($tpl);
	}
}